
//挂号信息表
const express = require('express');
const router = express.Router();
const RegistrationinforModel = require('../db/RegistrationinforMation');//挂号信息模型
const PatientModel = require('../db/PatientModel');
const fun = require('../middlewares/Fun');

router.post('/save', (req, res) => {
    let temp = new RegistrationinforModel(req.body);
    temp.save().then(docs => {
        return res.json({
            code: 200,
            mes: '添加成功。'
        });
    }).catch(() => {
        return res.json({
            code: 200,
            mes: '添加失败。'
        });
    })
});

router.post('/update', (req, res) => {
    let orderid = req.body.orderid;
    let payerid = req.body.payerid;
    let state = req.body.state;
    if (!orderid || !state || !payerid) {
        return res.json({
            code: 202,
            mes: '参数错误。'
        });
    }
    RegistrationinforModel.update({ orderid: orderid }, { $set: { receptionstate: state } }).then(docs => {
        return PatientModel.update({ _id: payerid }, { $set: { status: state } }).then(p => {
            return res.json({
                code: 200,
                mes: '修改成功。'
            });
        })
    }).catch(err => {
        return res.json({
            code: 201,
            mes: '修改失败。'
        });
    })
});
module.exports = router;